//
//  SKBaseNavigationController.m
//  SouthKoreaDoorLock
//
//  Created by Umeinfo on 2018/1/16.
//  Copyright © 2018年 andy90s. All rights reserved.
//

#import "SKBaseNavigationController.h"
#import "SKBaseViewController.h"
#import "SKBarButtonItem.h"
#import "DoorLockControlViewController.h"

@interface SKBaseNavigationController ()

@property (nonatomic, strong) UIView *barView;

@end

@implementation SKBaseNavigationController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setupViews];
}

- (void)setupViews {
    self.navigationBar.hidden = YES;
}



- (void)pushViewController:(UIViewController *)viewController animated:(BOOL)animated {
    if (self.childViewControllers.count > 0) {
        
        if ([viewController isKindOfClass:[SKBaseViewController class]]) {
            SKBaseViewController *vc = (SKBaseViewController *)viewController;
            vc.navItem.leftBarButtonItem = [[SKBarButtonItem alloc] initWithTitle:SKLANGUAGE(@"COMMON_NAV_BACK") fontSize:16 target:self action:@selector(popBack) isBackButton:YES];
        }
        if ([viewController isMemberOfClass:[DoorLockControlViewController class]]) {
            DoorLockControlViewController *vc = (DoorLockControlViewController *)viewController;
            vc.navItem.rightBarButtonItem = [[SKBarButtonItem alloc] initWithTitle:SKLANGUAGE(@"COMMON_NAV_REFRESH") fontSize:16 target:self action:@selector(rightItemButtonAction) isBackButton:NO];
        }
    }
    [super pushViewController:viewController animated:animated];
}



- (void)popBack {
    [self popViewControllerAnimated:YES];
}

- (void)rightItemButtonAction {
    if (_block) {
        _block();
    }
}

#pragma mark - lazy

- (UIView *)barView {
    if (!_barView) {
        _barView = [UIView new];
    }
    return _barView;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    
}

@end
